#include<iostream>
#include<string>
using namespace std;

int main(){
    //c++提供了两种风格的字符串
    //1、c风格字符串
    //2、c++引入的string类类型

    //1、c风格的字符串，就是char[],并在末尾加个\0
    char greeting[6] = "hello";//双引号定义会自动加\0
    //一些函数详见c/string.c，strlen(), strcpy(s1, s2), strcat(s1, s2)等

    //2、c++ string库 #include<string>
    string str1 = "hello";
    string str2 = "world";
    string str3;
    string str4 = "3";
    int len;

    //赋值，类似strcpy(str3, str1);
    str3 = str1;
    cout << "str3=:" << str3 <<endl;

    //连接，类似strcat(str1, str2);
    str3 = str1 + str2;
    cout << "str1 + str2 :" << str3 <<endl;

    //长度，类似strlen(str3)
    len = str3.size();
    cout << "str3.size():" << len << endl;

    //查找位置并且分隔
    int pos = 0;
    std::string subStr = " ";

    pos = str4.find(subStr, 0);
    cout << "str4.find('/', 0)=" << pos << endl;
    std::string array0, array1;
    array0 = str4.substr(0, pos);
    array1 = str4.substr(pos + subStr.length(), str4.length());
    cout << "array0=" << array0 << endl;
    cout << "array1=" << array1 << endl;

    //字符串转int
    std::string num = "100";
    //c 风格转换
    int t11 = atoi(num.c_str());
    //c++风格
    int t22 = std::stoi(num);
    
}